package com.project.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;

public class ListActivity extends AppCompatActivity {
    ListView musiclist;
    private List mplist;
    private List mp3list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        Intent intent = getIntent();
        musiclist = (ListView) findViewById(R.id.mulist);
        mplist = (ArrayList) intent.getSerializableExtra("m");
        Log.i("hahah", "............shishishs........." + mplist.size());
        mp3list = new ArrayList();
        Log.i("hahah", "................" + mplist.size());
        for (int i = 0; i < mplist.size(); i++) {
            Mp3 mp3 = new Mp3();
            mp3 = (Mp3) mplist.get(i);
            String info = mp3.getName() + "路径" + mp3.getUrl();
            Log.i("hahah", "................" + mp3.getName() + "路径" + mp3.getUrl());
            mp3list.add(info);
        }
        ArrayAdapter aa = new ArrayAdapter(this, R.layout.lv, mp3list);
        musiclist.setAdapter(aa);
        musiclist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent bintent = new Intent();
                Mp3 mp3 = (Mp3) mplist.get(position);
                Log.i("hahah", "..............." + mp3.getUrl());
                bintent.putExtra("url", mp3.getUrl());
                setResult(20, bintent);
                finish();
            }
        });
    }
}